let totalGems = randomNumberOfGems

var gemCounter = 0

func collectAndCountGem() {
    if isOnGem {
        collectGem()
        gemCounter += 1
    }
}

func flipSwitches() {
    pinkPortal.isActive = !pinkPortal.isActive
    bluePortal.isActive = !bluePortal.isActive
}

func turnAround() {
    turnLeft()
    turnLeft()
}

func action() {
    collectAndCountGem()
    
    moveForward()
    
    if isBlocked {
        turnAround()
        flipSwitches()
    }
}

while gemCounter != totalGems {
    action()
}
